//
//  YCNetworManager.h
//  YCSchool
//
//  Created by gmall on 16/5/6.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>

#pragma mark - UploadFileInfo

typedef NS_ENUM(NSUInteger,UploadFileType)
{
    UploadFileTypeImage = 1,
    UploadFileTypeVideo = 2,
    UploadFileTypeAudio = 3,
    UploadFileTypeHolder= 4,
};

@interface UploadFile : NSObject

@property (nonatomic,copy) NSString *localPath;
@property (nonatomic,copy) NSString *fileName;
@property (nonatomic,copy) NSString *mimeType;

@property (nonatomic,readonly) NSData *data;
@property (nonatomic,readonly) UploadFileType type;
@property (nonatomic,readonly) NSString *key;
@property (nonatomic,readonly) NSString *remotePath;
@property (nonatomic,copy) NSDictionary *extInfo;
@property (nonatomic,copy) NSString *urlKey;

+ (instancetype)uploadFileWihType:(UploadFileType)type data:(NSData *)data key:(NSString *)key;

@end



///服务端响应代码枚举
typedef NS_ENUM(NSUInteger, ServiceResponseCode)
{
    ///成功
    ServiceResponseSuccess = 1,
    ///权限限制
    ServiceResponseForbidden = 2,
    ///完善资料
    ServiceResponseCodeImproveInfo =100,
    ///传入参数错误
    ServiceResponseParamError = 400,
    ///系统异常
    ServiceResponseSystemError = 3,
    ///未知错误
    ServiceResponseUnknown = 5,
    ///原密码不正确
    ServiceResponse2010020 = 2010020,
    ///帐号和密码不匹配
    ServiceResponse1000003 = 1000003,
    ///令牌失效
    ServiceResponseTokenInvalidate  = 1000002,
};


#pragma mark - ServiceResponse

///接口响应类
@interface ServiceResponse : NSObject

///响应代码(code)
@property (nonatomic,readonly) ServiceResponseCode code;
///响应数据(data)
@property (nonatomic,readonly) id data;
///响应消息(message)
@property (nonatomic,readonly) NSString *message;
///接口是否正常返回数据
@property (nonatomic,readonly) BOOL success;

@end

#pragma mark - YCNetworkmagnager

/**
 *  调用接口成功回调
 *
 *  @param task      请求操作任务
 *  @param response  响应对象
 */
typedef void(^successBlock)(NSURLSessionDataTask *task, ServiceResponse *response);

/**
 *  调用接口失败回调
 *
 *  @param task      请求操作任务
 *  @param error     错误对象
 */
typedef void(^failureBlock)(NSURLSessionDataTask *task, NSError *error);

///接口调用对象
@interface YCNetworManager : NSObject

///接口地址
@property (nonatomic,copy) NSString *baseURLString;
///令牌
@property (nonatomic,copy) NSString *authToken;

@property (nonatomic,copy) NSString *userAgent;

/**
 *  获取接口调用对象单例
 *
 *  @return 接口调用对象单例
 */
+ (instancetype)shareManager;

/**
 *  GET方法调用接口
 *
 *  @param Url             接口路径(例:user/login)
 *  @param params          参数
 *  @param successCallBack 成功回调
 *  @param failureCallBack 失败回调
 *
 *  @return 请求操作
 */
- (NSURLSessionDataTask *)getWithUrl:(NSString *)Url
                               params:(NSDictionary *)params
                              success:(successBlock)successCallBack
                              failure:(failureBlock)failureCallBack;



/**
 *  POST请求
 *
 *  @param Url             接口路径(例:user/login)
 *  @param params          参数
 *  @param successCallBack 成功回调
 *  @param failureCallBack 失败回调
 *
 *  @return 请求操作
 */
- (NSURLSessionDataTask *)postWithUrl:(NSString *)Url
                                    params:(NSDictionary *)params
                                   success:(successBlock)successCallBack
                                   failure:(failureBlock)failureCallBack;

/**
 *  POST接口上传图片
 *
 *  @param Url          接口路径(例如:user/login)
 *  @param params          参数
 *  @param fileDatas       文件数据
 *  @param successCallBack 成功回调
 *  @param failureCallBack 失败回调
 *
 *  @return 请求操作
 */
- (NSURLSessionDataTask *)postWithUrl:(NSString *)Url
                                    params:(NSDictionary *)params
                                 fileDatas:(NSDictionary *)fileDatas
                                   success:(successBlock)successCallBack
                                   failure:(failureBlock)failureCallBack;

/**
 *  POST接口上传文件
 *
 *  @param Url          接口路径(例:user/login)
 *  @param params          参数
 *  @param block           构造表单回调
 *  @param successCallBack 成功回调
 *  @param failureCallBack 失败回调
 *
 *  @return 请求操作
 */
- (NSURLSessionDataTask *)postWithUrl:(NSString *)Url
                                    params:(NSDictionary *)params
                 constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block
                                   success:(successBlock)successCallBack
                                   failure:(failureBlock)failureCallBack;

@end
